#include <iostream>
#include <Eigen/Dense>
#include <opencv2/core.hpp>
#include <opencv2/core/eigen.hpp>
#include <opencv2/opencv.hpp>

int main() {
    // Load image
    cv::Mat image = cv::imread("../pic.png", cv::IMREAD_GRAYSCALE);
    if (image.empty()) {
        std::cerr << "Error: Could not load image!" << std::endl;
        return -1;
    }

    // Show original grayscale image
    cv::imshow("Original GrayScale Image", image);

    // Convert OpenCV Mat to Eigen Matrix
    Eigen::MatrixXd eigenMat;
    cv::cv2eigen(image, eigenMat);

    // Adjust brightness (increase by 50) and contrast (multiply by 1.2)
    double brightnessFactor = 50.0;
    double contrastFactor = 1.2;
    eigenMat = (eigenMat.array() * contrastFactor + brightnessFactor).unaryExpr([](double val) {
        return std::min(255.0, std::max(0.0, val));
    });

    // Convert Eigen matrix back to OpenCV Mat (CV_8U) for display
    cv::Mat displayMat;
    cv::eigen2cv(eigenMat, displayMat);
    displayMat.convertTo(displayMat, CV_8U);

    // Show the processed image
    cv::imshow("Processed Image", displayMat);
    cv::waitKey(0);

    return 0;
}